package com.tqjc.common.ScheduledTask;

import com.tqjc.utils.PlcOperator;
import com.tqjc.work.TaskStatus;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @projectName: BaotouSteel
 * @className: WordStatusScheduled
 * @author: Patienyon
 * @description: 工作状态定时任务
 * @date: 2023-06-29 16:07
 */
@Service
public class WorkStatusScheduleTask {


    @Resource
    TaskStatus taskStatus;

    @Resource
    PlcOperator plcOperator;


    /**
     * @param :
     * @return void
     * @author Patienyon
     * @description 更新发送给前端的工作状态
     * @date 2023-06-29 16:24
     */
    @Scheduled(cron = "0/2 * *  * * ? ")
    public void updateWorkStatus() {
        /*List<String> craneList = NormalConst.CRANE_LIST;
        for (String s : craneList) {
            boolean nowLogo = craneWorkFactory.getCraneWorkImpl(s).getData().getStartLogo();
            boolean nowsemiLogo = craneWorkFactory.getCraneWorkImpl(s).getData().getSemiAutoRunFlag();
            if (nowLogo||nowsemiLogo) {
                WorkStatus workStatus = taskStatus.getWorkStatusByCraneType(s);
                workStatus.setNowStatus("运行中");
                taskStatus.setWorkStatusByCraneType(s, workStatus);
            } else {
                WorkStatus workStatus = taskStatus.getWorkStatusByCraneType(s);
                workStatus.setNowStatus("未开始");
                taskStatus.setWorkStatusByCraneType(s, workStatus);
            }
        }*/
    }


//    @Scheduled(cron = "0/2 * *  * * ? ")
//    public void updateWorkStatus() {
//        List<String> craneList = NormalConst.CRANE_LIST;
//        for (String s : craneList) {
//            boolean nowLogo = craneWorkFactory.getCraneWorkImpl(s).getData().getStartLogo();
//            if (nowLogo) {
//                WorkStatus workStatus = taskStatus.getWorkStatusByCraneType(s);
//                workStatus.setNowStatus("运行中");
//                taskStatus.setWorkStatusByCraneType(s, workStatus);
//            } else {
//                WorkStatus workStatus = taskStatus.getWorkStatusByCraneType(s);
//                workStatus.setNowStatus("未开始");
//                taskStatus.setWorkStatusByCraneType(s, workStatus);
//            }
//        }
//    }

}
